package com.koron.css2.clientCenter.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.clientCenter.bean.UserReuseBean;
import com.koron.css2.clientCenter.mapper.ReuseUserMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.util.Constant;
import com.koron.util.JsonUtils;
import com.koron.util.ValidationKey;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

/**
 * 用户复用编辑
 * 
 * @author 甄玉晴
 *
 */
public class ReuseUserUpdate implements ServerInterface {

	@Override
	@ValidationKey(clazz = UserReuseBean.class,method = "update")
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		try {
			ReuseUserMapper mapper = factory.getMapper(ReuseUserMapper.class);
			UserReuseBean bean = JsonUtils.objectToPojo(req.getData(), UserReuseBean.class);
			// 获取停用信息
			//查询用户水表是否已拆表，如果拆表了，则需要复表
			String meterStatus=mapper.userMeterStatus(bean.getUserNo());
			if(!"2".equals(meterStatus)) {
				bean.setReuseMeterFlag(1);
			}
			bean.setUpdateInfo(userInfo);
			// 记录复用信息
			mapper.userReuseUpdate(bean);
			return MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", void.class);
		} catch (Exception e) {
			logger.error("非法参数", e);
			return MessageBean.create(Constant.ILLEGAL_PARAMETER, "非法参数", void.class);
		}
	}

}
